import BaiduCloudClientBaseConfig from './config';
export class BaiduCloudClient {
  private sdk;
  private init_config: InitConfigTypes;
  private params: object;
  private body;
  private method: string;
  private path: string;
  private headers: object;
  private client: any;
  constructor(params: BaiduCloudClientTypes) {
    this.sdk = require('@baiducloud/sdk');
    this.init_config = {
      ak: params.init_config.ak || BaiduCloudClientBaseConfig.ak,
      sk: params.init_config.sk || BaiduCloudClientBaseConfig.sk,
      endpoint:
        params.init_config.endpoint || BaiduCloudClientBaseConfig.endpoint,
    };
    this.params = params.request.args.params;
    this.body = params.request.args.body;
    this.method =
      params.request.config.method || BaiduCloudClientBaseConfig.method;
    this.path = params.request.config.path;
    this.headers = params.request.config.headers || {
      'Content-Type': BaiduCloudClientBaseConfig.contentType,
    };
  }

  public init() {
    this.client = new this.sdk.HttpClient(this.init_config);
  }

  // eslint-disable-next-line @typescript-eslint/no-empty-function
  public async sendRequest() {
    return await this.client.sendRequest(
      'POST',
      this.params,
      this.body,
      this.headers,
      this.params,
    );
  }

  public getConfig() {
    return {
      config: this.init_config,
      params: this.params,
      body: this.body,
      method: this.method,
      path: this.path,
      headers: this.headers,
    };
  }
}
